package hw524919.lesson1;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class SortWithNumber {
	public static void main(String[] args) {
		SortWithNumber sortWithNumber = new SortWithNumber();
		sortWithNumber.sortMethod1();
		sortWithNumber.sortMethod2();
		sortWithNumber.sortMethod3();
		sortWithNumber.sortMethod4();
		sortWithNumber.sortMethod5();
		sortWithNumber.sortMethod6();
		sortWithNumber.sortMethod7(1);
	}

	public void sortMethod1() {
		System.out.println("For语句方法1");
		for (int i = 1; i <= 100; i++) {
			if (i == 47)
				break;
			System.out.println(i);
		}
	}

	public void sortMethod2() {
		int i = 1;
		System.out.println("While语句i++方法2");
		while (i <= 100) {
			if (i == 47)
				break;
			System.out.println(i);
			i++;
		}
	}

	public void sortMethod3() {
		int i = 0;
		System.out.println("while语句++i方法3");
		while (i < 100) {
			++i;
			if (i == 47)
				break;
			System.out.println(i);
		}
	}

	public void sortMethod4() {
		int i = 1;
		System.out.println("do while语句i++方法4");
		do {
			if (i == 47)
				break;
			System.out.println(i++);
		} while (i <= 100);
	}

	public void sortMethod5() {
		List<Integer> numi = getList();
		System.out.println("List方法5");
		for (Integer n : numi) {
			if (n == 47)
				break;
			System.out.println(n);
		}

	}

	public void sortMethod6() {
		int i = 1;
		List<Integer> numi = getList();

		System.out.println("iterator方法6");
		Iterator<Integer> iterator = numi.iterator();
		while (true) {
			if (iterator.hasNext()) {
				i = iterator.next().intValue();
				if (i == 47)
					break;
				System.out.println(i);
			} else {
				break;
			}
		}
	}

	public void sortMethod7(int i) {
		if (i < 101) {
			System.out.println(i);
			if (i == 47)
				return;
			i++;
			this.sortMethod7(i);
		} else {
			return;
		}
	}

	private List<Integer> getList() {
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 1; i <= 100; i++) {
			list.add(i);
		}
		return list;
	}
}
